package com.artpri.action.goods;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.artpri.action.BaseAction;
import com.artpri.model.GoodsCategory;
import com.artpri.model.vo.GoodAttributeVo;
import com.artpri.model.vo.SimpleGoods;
import com.artpri.service.GoodsCategoryService;

/**
 * 商品筛选器
 * @author ZhangSi
 */
public class GoodsFilterAction extends BaseAction{

	private static final long serialVersionUID = 1L;

	private List<GoodAttributeVo> goodAttrs;
	
	private List<SimpleGoods> goods;
	
	private Integer gcgId; //分类群组ID
	
	private List<GoodsCategory> categories; //艺术分类
	
	private Integer rtype; //类型
	
	private String price; //价格
	
	private String local; //所在地
	
	private Integer themeId;
	private String theme; //题材
	
	private Integer textureId;
	private String texture; //材质
	
	private Integer techniqueId;
	private String technique; //技法
	
	private Integer shapeId;
	private String shape; //形制
	
	private Integer styleId;
	private String style; //作品风格
	
	private Integer fontId;
	private String font; //字体
	
	private Integer pageNo;
	private Integer totalPage;
	private Integer totalRecords;
	private Integer pageSize;
	
	@Override
	public String execute() throws Exception {
	
		//0.根据分组ID获取艺术分类
		categories = getGoodsCategoryService().getCategoryByGroup(gcgId);
		
		//1.获取类型属性
		if (rtype != null) {
			GoodsCategory topCategory = getGoodsCategoryService().getTopCategory(rtype);
			goodAttrs = getGoodAttributeService().getGoodAttributeVoByCategory(topCategory.getGcId());
		}
		//2.获取作品对象列表
		Map<Integer, String> map = new HashMap<Integer, String>();
		map.put(fontId, font);
		map.put(shapeId, shape);
		map.put(styleId, style);
		map.put(themeId, theme);
		map.put(textureId, texture);
		map.put(techniqueId, technique);
		
		Map<Integer, List<SimpleGoods>> result = getGoodsFilterService().getFilterResult(rtype, price, local, map, getPageNo(), pageSize);
		
		//获取总记录条数和页面数量
		for (Entry<Integer, List<SimpleGoods>> type : result.entrySet()) {
			goods = type.getValue();
			totalRecords = type.getKey();
		}
		totalPage = totalRecords%pageSize==0 ? totalRecords/pageSize : totalRecords/pageSize +1;
		
		return SUCCESS;
	}


	
	public List<GoodsCategory> getCategories() {
		return categories;
	}

	public void setCategories(List<GoodsCategory> categories) {
		this.categories = categories;
	}

	public Integer getGcgId() {
		return gcgId;
	}

	public void setGcgId(Integer gcgId) {
		this.gcgId = gcgId;
	}

	public List<GoodAttributeVo> getGoodAttrs() {
		return goodAttrs;
	}

	public void setGoodAttrs(List<GoodAttributeVo> goodAttrs) {
		this.goodAttrs = goodAttrs;
	}

	public List<SimpleGoods> getGoods() {
		return goods;
	}

	public void setGoods(List<SimpleGoods> goods) {
		this.goods = goods;
	}

	public Integer getThemeId() {
		return themeId;
	}
	
	public void setThemeId(Integer themeId) {
		this.themeId = themeId;
	}

	public Integer getTextureId() {
		return textureId;
	}

	public void setTextureId(Integer textureId) {
		this.textureId = textureId;
	}

	public Integer getTechniqueId() {
		return techniqueId;
	}

	public void setTechniqueId(Integer techniqueId) {
		this.techniqueId = techniqueId;
	}

	public Integer getShapeId() {
		return shapeId;
	}

	public void setShapeId(Integer shapeId) {
		this.shapeId = shapeId;
	}

	public Integer getStyleId() {
		return styleId;
	}

	public void setStyleId(Integer styleId) {
		this.styleId = styleId;
	}

	public Integer getFontId() {
		return fontId;
	}

	public void setFontId(Integer fontId) {
		this.fontId = fontId;
	}

	public void setRtype(Integer rtype) {
		this.rtype = rtype;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public void setLocal(String local) {
		this.local = local;
	}

	public void setTheme(String theme) {
		this.theme = theme;
	}

	public void setTexture(String texture) {
		this.texture = texture;
	}

	public void setTechnique(String technique) {
		this.technique = technique;
	}

	public void setShape(String shape) {
		this.shape = shape;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public void setFont(String font) {
		this.font = font;
	}

	public Integer getRtype() {
		return rtype;
	}

	public String getPrice() {
		return price;
	}

	public String getLocal() {
		return local;
	}

	public String getTheme() {
		return theme;
	}

	public String getTexture() {
		return texture;
	}

	public String getTechnique() {
		return technique;
	}

	public String getShape() {
		return shape;
	}

	public String getStyle() {
		return style;
	}

	public String getFont() {
		return font;
	}

	public Integer getPageNo() {
		pageNo = pageNo == null ? 1 : pageNo;
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getTotalRecords() {
		return totalRecords;
	}

	public void setTotalRecords(Integer totalRecords) {
		this.totalRecords = totalRecords;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
}


